package com.springboot.controller;

import com.springboot.domain.City;
import org.apache.catalina.User;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author fzc
 * @time 2017/6/23.
 */
@RestController
@RequestMapping("/city")
public class CityController {

    static Map<Long, City> citys = Collections.synchronizedMap(new HashMap<Long, City>());

    @RequestMapping(value = "/{id}/detail")
    public City getCityById(@PathVariable Long id) {
        return citys.get(id);
    }

    @RequestMapping(value = "/{id}/del",method = RequestMethod.DELETE)
    public City delCityById(@PathVariable Long id) {
        City remove = citys.remove(id);
        return remove;
    }
    @RequestMapping(value = "/list")
    public List<City> listCity() {
        return new ArrayList<>(citys.values());
    }
    @RequestMapping(value = "/")
    public String putCity(City city) {
        citys.put(city.getId(), city);
        return "success";
    }
}
